import HttpKit from '@/utils/http-kit'

export default {
  /**
   * @description 获取用户列表
   * @returns {Promise<T | never>}
   */
  getUserList () {
    return HttpKit.get('/users', {}).then(
      res => res
    )
  },
  /**
   * @description 管理员可以添加用户，一般用于添加业务员和工人用户
   * @param user
   * @returns {Promise<T | never>}
   */
  addUser (user) {
    return HttpKit.post('/user/add', {
      'account': user.accountId,
      'id': 0,
      'location': user.location,
      'password': user.password,
      'phone': user.telephone,
      'roleCode': user.roleCode
    }).then(
      res => res
    )
  },
  /***
   * @description 管理员删除用户
   * @param userId
   * @returns {Promise<T | never>}
   */
  deleteUser (userId) {
    return HttpKit.delete('/user/delete/' + userId, {}).then(
      res => res
    )
  },
  /**
   * @description 用户修改密码
   * @param user
   * @returns {Promise<T | never>}
   */
  changePassword (user) {
    return HttpKit.get('/user/changePassword', {password: user.password, userId: user.accountId}).then(
      res => res
    )
  },
  /**
   * @description 用户修改个人信息
   * @param user
   * @returns {Promise<T | never>}
   */
  changeInformation (user) {
    return HttpKit.get('/user/changePhone', {phone: user.phone, userId: user.accountId}).then(
      res => res
    )
  },
  /**
   * @description 验证用户
   * @param user
   * @returns {Promise<T | never>}
   */
  findUser (user) {
    return HttpKit.get('/user/findUser', {account: user.account, phone: user.phone}).then(
      res => res
    )
  },
  /**
   * @description 通过用户id得到用户电话号码
   * @param id
   * @returns {Promise<T | never>}
   */
  getPhone (id) {
    return HttpKit.get('/user/getPhone', {userId: id}).then(
      res => res
    )
  }
}
